import smtplib
import time
from email.mime.text import MIMEText
from email.header import Header
from email.mime.multipart import MIMEMultipart
# 发送邮箱服务器
smtpserver = "smtp.qq.com"

# 发送邮箱用户名密码
user = "2536451342@qq.com"
password = "ajvcntawwtbuebdd"

# 发送和接收邮箱
sender = "2536451342@qq.com"
receive = "2951609504@qq.com"

# 发送邮件主题和内容
subject = "雷佳胜html报告"
content = "<html><h1 style=''></h1></html>"

# HTML邮件正文
msg = MIMEText(content, 'html', 'utf-8')
msg['Subject'] = Header(subject, 'utf-8')
msg['From'] = "2536451342@qq.com"
msg['To'] = "294349824@qq.com"
send_file = open(r"E:\PythonTest\venv\html\CalcReport.html", "rb").read()

att = MIMEText(send_file, "base64", 'utf-8')
att['Content-Type'] = 'application/octet-stream'
att['Content-Disposition'] = 'attachment;filename="logo.html"'

msgRoot = MIMEMultipart()
msgRoot.attach(MIMEText(content, 'html', 'utf-8'))
msgRoot['Subject'] = subject
msgRoot['From'] = sender
msgRoot['To'] = ','.join(receive)
msgRoot.attach(att)
#...
# smtp.sendmail(sender, receive, msgRoot.as_string())

# SSL协议端口号要使用465
smtp = smtplib.SMTP_SSL(smtpserver, 465)

# HELO向服务器标志用户身份
smtp.helo(smtpserver)

# 服务器返回结果确认
smtp.ehlo(smtpserver)

# 登录邮箱服务器用户名密码
smtp.login(user, password)

smtp.sendmail(sender, receive, msgRoot.as_string())
print("Send email start...")
smtp.sendmail(sender, receive, msg.as_string())
smtp.quit()
print("email send end!")